home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / misc / VMM_src.lha / VMM / sv_regs851.asm < prev    next >
Encoding:
Assembly Source File  |  1995-12-16  |  6.3 KB  |  193 lines

  1.                INCLUDE   "exec/funcdef.i"
  2.                INCLUDE   "exec/exec_lib.i"
  3.                INCLUDE   "macros.i"
  4.                INCLUDE   "shared_defs.i"
  5.  
  6. * $Id: sv_regs851.asm,v 3.5 95/12/16 18:36:39 Martin_Apel Exp $
  7.  
  8.                XDEF      _MMU68851
  9.                XDEF      _GenDescr851
  10.  
  11.                XDEF      _SetMMUState851
  12.                XDEF      _ReadMMUState851
  13.                XDEF      _SaveMMUState851
  14.                XDEF      _RestoreMMUState851
  15.  
  16.  
  17. TCB_E          EQU       31                  ; Translation control: enable
  18. TCF_E          EQU       (1<<31)
  19. SRB_I          EQU       10                  ; MMUSR: Invalid
  20. SRF_I          EQU       (1<<10)
  21. SRB_T          EQU       6                   ; MMUSR: TT hit
  22. SRF_T          EQU       (1<<6)
  23. PDB_CI         EQU       6                   ; Page descr: cache inhibit
  24. PDF_CI         EQU       (1<<6)
  25. PDB_WP         EQU       2                   ; Page descr: write protected
  26. PDF_WP         EQU       (1<<2)
  27.  
  28.  
  29.                MACHINE   68020
  30.                PMMU
  31.  
  32.                SECTION   CODE
  33.  
  34. _MMU68851:     * Checks if there is a working 68851 MMU in the system
  35.                * No need to take care of caches because this is only called
  36.                * on 68020 systems
  37.  
  38.                PRINT_DEB "Checking for 68851"
  39.                movem.l   a5-a6,-(sp)
  40.                move.l    4,a6
  41.                lea       Check851(pc),a5
  42.                jsr       _LVOSupervisor(a6)
  43.                movem.l   (sp)+,a5-a6
  44.                rts
  45.  
  46. Check851:      movec     VBR,a0
  47.                lea       11*4(a0),a0
  48.                move.l    (a0),d1                  ; old LINE-F vector
  49.                lea       Trap851(pc),a1
  50.                move.l    a1,(a0)
  51.                moveq     #1,d0
  52.                pmove     tc,-4(sp)                ; might cause trap
  53.                move.l    d1,(a0)                  ; restore original LINE-F vector
  54.                * d0 contains if valid 68851 recognized
  55.                rte
  56.                
  57.  
  58. Trap851:       moveq     #0,d0
  59.                PRINT_DEB "68851 NOT detected"
  60.                add.l     #6,2(sp)                 ; skip causing instruction
  61.                rte
  62.  
  63. ***********************************************
  64.  
  65. _SaveMMUState851:
  66.                * Saves the current MMU registers into a private buffer.
  67.                * No inputs, no outputs
  68.                lea       _PrivateMMUState(pc),a0
  69.                move.l    a0,-(sp)
  70.                bsr       _ReadMMUState851
  71.                addq      #4,sp
  72.                lea       _MMUStateValid(pc),a0
  73.                move.w    #1,(a0)
  74.                rts
  75.  
  76. ***********************************************
  77.  
  78. _RestoreMMUState851:
  79.                * Restore the MMU registers from the private buffer.
  80.                * No inputs, no outputs
  81.  
  82.                tst.w     _MMUStateValid(pc)
  83.                beq       Ready
  84.                lea       _PrivateMMUState(pc),a0
  85.                move.l    a0,-(sp)
  86.                bsr       _SetMMUState851
  87.                addq      #4,sp
  88. Ready          rts
  89.  
  90. ***********************************************
  91.  
  92. _MMUStateValid dc.w       0
  93. _PrivateMMUState:
  94.                ds.b       MS30_SIZE
  95.  
  96. ***********************************************
  97.  
  98. _SetMMUState851:
  99.                * Called from C as:
  100.                * void SetMMUState851 (MMUState851*)
  101.  
  102.                movem.l   a5-a6,-(sp)
  103.                move.l    12(sp),a0
  104.                move.l    4,a6
  105.                lea       SetMMUState851(pc),a5
  106.                jsr       _LVOSupervisor(a6)
  107.                movem.l   (sp)+,a5-a6
  108.                rts
  109.  
  110. SetMMUState851 lea       -4(sp),a1                ; reserve long-word on stack
  111.                clr.l     (a1)
  112.                pmove     (a1),TC                  ; MMU ausschalten
  113.  
  114.                pmove     MS30_CRP_HI(a0),CRP
  115.                pmove     MS30_SRP_HI(a0),SRP
  116.                pmove     MS30_TC(a0),TC           ; MMU einschalten
  117.                PRINT_DEB "MMU registers set"
  118.  
  119.                rte
  120.  
  121. ***********************************************
  122.  
  123. _ReadMMUState851:
  124.                * Called from C as:
  125.                * void ReadMMUState851 (MMUState851*)
  126.  
  127.                movem.l   a5-a6,-(sp)
  128.                move.l    12(sp),a0                   ; start address of MMUState
  129.                move.l    4,a6
  130.                lea       ReadMMUState851(pc),a5
  131.                jsr       _LVOSupervisor(a6)
  132.                movem.l   (sp)+,a5-a6
  133.                rts
  134.  
  135. ReadMMUState851:
  136.                pmove     TC,MS30_TC(a0)
  137.                pmove     CRP,MS30_CRP_HI(a0)
  138.                pmove     SRP,MS30_SRP_HI(a0)
  139.                rte
  140.  
  141. ***********************************************
  142.  
  143. _GenDescr851:  * This function generates an MMU page descriptor for
  144.                * a given logical address. It includes all the standard
  145.                * information a page descriptor contains. 
  146.                * C prototype:
  147.                *  ULONG GenDescr (ULONG LogAddr);
  148.  
  149.                movem.l   a5-a6,-(sp)
  150.                move.l    4,a6
  151.                move.l    12(sp),a0
  152.                PRINT_DEB "GenDescr851 called for address %08lx",a0
  153.                lea       GenDescr(pc),a5
  154.                jsr       _LVOSupervisor(a6)
  155.                movem.l   (sp)+,a5-a6
  156.                rts
  157.  
  158. GenDescr:      * If MMU is turned off, no PTEST instruction must be executed.
  159.                sub.w     #4,sp
  160.                pmove     tc,(sp)
  161.                move.l    (sp)+,d0
  162.                btst.l    #TCB_E,d0
  163.                beq       MMUOff
  164.  
  165.                * Check if there is a valid table mapping for this address
  166.                sub.w     #2,sp
  167.                ptestr    #1,(a0),#7,a1
  168.                pmove     mmusr,(sp)
  169.                move.w    (sp)+,d0
  170.                btst.l    #SRB_I,d0
  171.                bne       InvalidTranslation
  172.  
  173.                * there is a valid mapping: Extract the physical address,
  174.                * the WP and cache mode.
  175.                move.l    (a1),d0
  176.                and.w     #((~(PAGESIZE-1))|PDF_CI|PDF_WP),d0
  177.                bset.l    #0,d0                    ; make resident
  178.                rte
  179.                
  180. MMUOff:        * MMU is turned off. Return the logical address as
  181.                * the physical address
  182.                move.l    a0,d0
  183.                and.w     #~(PAGESIZE-1),d0
  184.                bset.l    #0,d0                    ; make resident, cacheable
  185.                rte
  186.  
  187. InvalidTranslation:
  188.                * return illegal descriptor
  189.                moveq     #0,d0
  190.                rte
  191.  
  192.                END
  193.